package com.ztgf.shopping.service.template;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.ztgf.shopping.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.shopping.mapper.template.ContractTempletMapper;
import com.ztgf.shopping.models.service.template.IContractTempletService;
import com.ztgf.shopping.models.bo.template.ContractTempletSaveBO;
import com.ztgf.shopping.models.dto.template.ContractTempletDTO;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 合同模版控制器
 *
 * @author YUE
 * @Date 2020-05-28 16:00:46
 */
@DubboService
public class ContractTempletServiceImpl extends ServiceImpl<ContractTempletMapper, ContractTempletDTO> implements IContractTempletService{

    @Resource
    private YmlConfig ymlConfig;

    @Autowired
    private ContractTempletMapper contractTempletMapper;

    @Override
    public boolean add(ContractTempletSaveBO saveBO) {
        ContractTempletDTO dto = new ContractTempletDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    /**
     * 获取默认合同模板
     * @return
     */
    public ContractTempletDTO getDefaultContract(){
        ContractTempletDTO contractTempletDTO = new ContractTempletDTO();
        contractTempletDTO.setIsDefault(0);
        return contractTempletMapper.selectOne(contractTempletDTO);
    }

    /**
     * 获取合同模板根据契约锁模板id
     * @return
     */
    @Override
    public ContractTempletDTO getTemplateByTemId(String templateId){
        ContractTempletDTO contractTempletDTO = new ContractTempletDTO();
        contractTempletDTO.setTemplateId(templateId);
        contractTempletDTO.setIsDefault(0);
        return contractTempletMapper.selectOne(contractTempletDTO);
    }
}
